'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 副本通关条件判断
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var eventConditionType = require('../consts/eventConditionType');
var ecHeroLv = require('./eventCondition/ecHeroLv');
var ecSoldierLv = require('./eventCondition/ecSoldierLv');
var ecSoldierNum = require('./eventCondition/ecSoldierNum');
var ecSoldierTrainLv = require('./eventCondition/ecSoldierTrainLv');
var dataApi = require('../libs/dataApi');

var event_condition_instances = {};

// 1.英雄达到$1级
event_condition_instances[eventConditionType.HERO_LV] = function () {
    return ecHeroLv;
};

// 2.$1兵种达到$2级
event_condition_instances[eventConditionType.SOLDIER_LV] = function () {
    return ecHeroLv;
};

// 3.$1兵种精锐等级达到$2级
event_condition_instances[eventConditionType.SOLDIER_TRAIN_LV] = function () {
    return ecHeroLv;
};

// 4.$1兵种达到$2个
event_condition_instances[eventConditionType.SOLDIER_NUM] = function () {
    return ecHeroLv;
};

/**
 * 判断条件是否满足
 * @param  {[type]}  build_list [description]
 * @param  {[type]}  road_list  [description]
 */
exports.check = function (event_type, role_model, soldier_model) {
    var event_star_conf = dataApi.event_star.findById(event_type);
    var instance = _getInstance(event_star_conf.star_type);
    return instance.check(event_star_conf, role_model, soldier_model);
};

var _getInstance = function (condition_type) {
    var instance = event_condition_instances[condition_type];
    if (!!instance) {
        return instance();
    } else {
        throw new Error('copy condition type can not found:' + condition_type);
    }
};
